package com.hjc.springbootmovies.controller;

import com.hjc.springbootmovies.entity.ModelBroad;
import com.hjc.springbootmovies.service.Impl.BoradServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/12/4
 * Time: 14:34
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/borad")
public class BoradController {
    @Autowired
    private BoradServiceImpl boradService;

    @GetMapping("boradControllerAll")
    public String boradAll(){
        return "html/borad/all";
    }

    @GetMapping("boradControllerAdd")
    public String boradAdd(){
        return "html/borad/add";
    }

    @GetMapping("boradControllerUpdate")
    public String boradUpdate(int xid , Model model){
        model.addAttribute("update", boradService.queryById(xid));
        return "html/borad/update";
    }

    @RequestMapping(value = "addBorad" , method = RequestMethod.POST)
    public String addBorad(ModelBroad modelBroad){
        int count = boradService.addBroad(modelBroad);
        return "html/borad/all";
    }

    @RequestMapping(value = "deleteById" , method = RequestMethod.GET)
    public String deleteById(int xid){
        int count = boradService.deleteById(xid);
        return "html/borad/all";
    }

    @RequestMapping(value = "updateBroad" , method = RequestMethod.POST)
    public String updateBroad(ModelBroad modelBroad){
        int count = boradService.updateBroad(modelBroad);
        return "html/borad/all";
    }
}
